package com.snut.tomorrowNews.controller.back;

import com.snut.tomorrowNews.common.CommonResult;
import com.snut.tomorrowNews.model.Menu;
import com.snut.tomorrowNews.model.Role;
import com.snut.tomorrowNews.service.back.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping(path = "/role")
public class RoleController {

    @Autowired
    RoleService roleService;

    /**
     * 查询角色列表
     * @return
     */
    @RequestMapping(path = "/roles")
    public CommonResult roles(){
      CommonResult commonResult = null;
         try {
             List<Role> roles = roleService.getRoleList();
             commonResult = new CommonResult(200, "查询成功", roles);
         }catch (Exception e){
             e.printStackTrace();
             commonResult = new CommonResult(500, "查询失败",null);
         }
         return commonResult;
     }

    /**
     * 查询菜单列表
     * @return
     */
    @RequestMapping(path = "/menus")
    public CommonResult menus(){
        CommonResult commonResult = null;
        try {
            List<Menu> menus = roleService.getMenuList();
            commonResult = new CommonResult(200, "查询成功", menus);
        }catch (Exception e){
            e.printStackTrace();
            commonResult = new CommonResult(500, "查询失败",null);
        }
        return commonResult;
    }
}
